package com.link.base.base.pubacctorgmapping.controller;

import com.link.base.base.pubacctorgmapping.model.PubAcctOrgMapping;
import com.link.base.base.pubacctorgmapping.service.PubAcctOrgMappingService;
import com.link.base.core.basic.util.CodeCleanUtils;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import com.link.core.cllog.LCLogger;
import com.link.core.util.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 微信公众号组织映射-
 *
 * @author 安小波
 * @date 2019/04/15 17:18
 */
@Controller
@RequestMapping("/link/pubAcctOrgMapping")
public class PubAcctOrgMappingController extends BasicController<PubAcctOrgMapping> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private PubAcctOrgMappingService pubAcctOrgMappingService;

    @Override
    public BasicService<PubAcctOrgMapping> getBasicService() throws Exception {
        return pubAcctOrgMappingService;
    }

    /**
     * 根据微信appId找对应组织
     *
     * @param entity
     * @author anxiaobo
     * @date 2019/5/7 11:55
     */
    @RequestMapping({"/queryByWxAppId"})
    @ResponseBody
    public Map<String, Object> queryByWxAppId(@RequestBody PubAcctOrgMapping entity) {
        Map<String, Object> result = CodeCleanUtils.cast(new HashMap(16));
        try {
            if (StringUtils.isBlank(entity.getPublicAccount())) {
                result.put("success", false);
                result.put("message", "微信appId为空");
                return result;
            }
            PubAcctOrgMapping pubAcctOrgMapping = pubAcctOrgMappingService.queryByWxAppId(entity);
            result.put("result", pubAcctOrgMapping);
            result.put("success", true);
            result.put("message", "获取组织成功!");
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }
}
